package flink.demo;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

public class StreamConnect_Union_Demo {

    public static void main(String[] args) throws Exception {

        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port", 8822);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration);
        env.setParallelism(1);


        DataStreamSource<String> one = env.socketTextStream("localhost", 9999);

        DataStreamSource<String> two = env.socketTextStream("localhost", 9998);
        ConnectedStreams<String, String> connect = two.connect(one);

        connect.map(new CoMapFunction<String, String, String>() {
            @Override
            public String map1(String s) throws Exception {
                return s;
            }

            @Override
            public String map2(String s) throws Exception {
                return s;
            }
        });


        DataStream<String> union = one.union(two);
        union.map(new MapFunction<String, String>() {

            @Override
            public String map(String s) throws Exception {
                return s;
            }
        });

        env.execute();


    }

}
